package com.share.tool.generator.sql_convert;

import com.share.tool.generator.sql_convert.util.ConvertUtil;
import com.share.tool.generator.sql_convert.util.ReadUtil;
import com.share.tool.generator.sql_convert.vo.Column;
import com.share.tool.generator.sql_convert.vo.Table;
import lombok.extern.slf4j.Slf4j;

import java.util.LinkedList;
import java.util.List;

@Slf4j
public class MainConvert {
    public static void main(String[] args) {
        //读取表信息
//        List<Table> list = ReadUtil.readInsertSql();
        List<Table> list = ReadUtil.readTableStructure();

        List<String> retList = new LinkedList<>();
        //遍历结果
        for (Table tab : list) {
            String res = null;
            String tableName = tab.getTableName();
            String tableComment = tab.getTableComment();
            List<Column> tmpList = tab.getColumnList();
            log.info("正在处理了表tableName={},tableComment={}", tableName, tableComment);
            res = ConvertUtil.toJavaModel(tableName, tmpList);
            retList.add(res);

            res = ConvertUtil.deleteByIdAndCode(tableName, tmpList);
            retList.add(res);

            res = ConvertUtil.insertIfTest(tableName, tmpList);
            retList.add(res);

            res = ConvertUtil.insertbatch(tableName, tmpList);
            retList.add(res);

            res = ConvertUtil.createSqliteTable(tableName, tmpList);
            retList.add(res);

            res = ConvertUtil.updateIfTestById(tableName, tmpList);
            retList.add(res);
        }

        //打印信息
        retList.forEach(e -> System.out.println(e));
    }
}
